package com.teamone.etl.accountant.service.impl;

import com.teamone.etl.accountant.feign.EnterpriseFeign;
import com.teamone.etl.accountant.entity.PersonalInformation;
import com.teamone.etl.accountant.dao.PersonalInformationDao;
import com.teamone.etl.accountant.service.PersonalInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * 个人账户信息(PersonalInformation)表服务实现类
 *
 * @author makejava
 * @since 2021-01-20 15:22:26
 */
@Service("personalInformationService")
@Transactional(rollbackFor = Exception.class)
public class PersonalInformationServiceImpl implements PersonalInformationService {
    @Resource
    private PersonalInformationDao personalInformationDao;

    @Autowired
    private EnterpriseFeign enterpriseFeign;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PersonalInformation queryById(Integer id) {
        return this.personalInformationDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<PersonalInformation> queryAllByLimit(int offset, int limit) {
        return this.personalInformationDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param personalInformation 实例对象
     * @return 实例对象
     */
    @Override
    public PersonalInformation insert(PersonalInformation personalInformation) {
        this.personalInformationDao.insert(personalInformation);
        return personalInformation;
    }

    /**
     * 修改数据
     *
     * @param personalInformation 实例对象
     * @return 实例对象
     */
    @Override
    public PersonalInformation update(PersonalInformation personalInformation) {
        this.personalInformationDao.update(personalInformation);
        return this.queryById(personalInformation.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.personalInformationDao.deleteById(id) > 0;
    }

    @Override
    public int openWarning(Integer id, BigDecimal warningThreshold, String warningPhone) {
        return this.personalInformationDao.openWarning(id,warningThreshold,warningPhone);
    }

    @Override
    public int closeWarning(Integer id) {
        return this.personalInformationDao.closeWarning(id);
    }

    @Override
    public PersonalInformation personalInformation(Integer id) {
        return this.personalInformationDao.personalInformation(id);
    }
}